package ru.housewife.controllers;

import ru.housewife.AppConstants;
import ru.housewife.form.UserForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * controller that is used only by authorized users
 *
 * @author Alexander Troshanin
 */
public abstract class AuthorizedController extends AbstractController {

    @Override
    public boolean checkAuth(HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (getUserForm(request) != null) {
            return true;
        }
        response.sendRedirect(AppConstants.LOGON_URL);
        return false;
    }

    protected UserForm getUserForm(HttpServletRequest request) {
        return (UserForm) request.getSession().getAttribute(AppConstants.SESSION_USER);
    }

}
